﻿Imports Framework

Public Class FEditMatchPattern
    Private mResult As Entities.MatchPattern

    Public Shadows Function ShowDialog(ByVal owner As Form, ByVal pattern As Entities.MatchPattern) As Entities.MatchPattern
        cboType.Items.Add("Wildcard (Simple. ie *.* or *.doc)")
        cboType.Items.Add("Regular Expressions (Complex)")
        Select Case pattern.Type
            Case Entities.MatchPatternType.RegEx
                cboType.SelectedIndex = 1
            Case Else
                cboType.SelectedIndex = 0
        End Select
        txtPattern.Text = pattern.Pattern

        MyBase.ShowDialog(owner)
        Return mResult
    End Function

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Try
            Dim clsPat As New Entities.MatchPattern
            Select Case cboType.SelectedIndex
                Case 0
                    clsPat.Type = Entities.MatchPatternType.WildCard
                Case 1
                    clsPat.Type = Entities.MatchPatternType.RegEx
                Case Else
                    Throw New NotImplementedException
            End Select
            clsPat.Pattern = txtPattern.Text.Trim

            If clsPat.IsValid Then
                mResult = clsPat
                Me.Close()
            Else
                MessageBox.Show(Me, "Pattern is not valid!", "Match Pattern", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
            End If
        Catch ex As Exception
            Framework.Misc.HandleException(Me, ex)
        End Try
    End Sub
End Class

